"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/10/25 9:34
@Description :   容器推导式

列表推导式:
   方式1: [表达式 for 变量 in 列表]
   方式2: [表达式 for 变量 in 列表 if 条件]

字典推导式：
{ key_expr: value_expr for value in collection }
或
{ key_expr: value_expr for value in collection if condition }

集合推导式:

{ expression for item in Sequence}
或
{ expression for item in Sequence if conditional }


元组推导式
(expression for item in Sequence )
或
(expression for item in Sequence if conditional )
"""
scores = [10, 20, 23, 50]
# 将列表中的分数提升 10分
new_scores = []
for score in scores:
    new_scores.append(score + 10)

# 遍历新列表
for score in new_scores:
    print(score)

# 列表推导式
new_scores = [score + 10 for score in scores]
print(new_scores)

new_scores = [score for score in scores if score >= 20]
print(new_scores)

# 字符串及其长度创建字典
list_info = ['Google', 'Runoob', 'Taobao']

info_dict = {key: len(key) for key in list_info}
print(info_dict)

num_set = {1, 2, 3, 4, 5, 6, 7, 8, 9}
new_num_set = {num for num in num_set if num % 2 != 0}
print(new_num_set)


num_tuple = (1, 2, 3, 4, 5, 6, 7, 8, 9)
new_num_tuple = (num for num in num_set if num % 2 != 0)   # 元组生成器
print(new_num_tuple,type(new_num_tuple))
result = tuple(new_num_tuple)
print(result,type(result))
